<!DOCTYPE html>
<html lang="en">
<head>
    <titleType style="display: none;">qyls</titleType>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>我的签约</title>
    <%- include('./_global/baseLibs') %>
    <link rel="stylesheet"  href="/static/css/mycontract.css" />

    <style>
        html,body{
            background: #fff;
        }

        .wdqy-select-box{
            max-height: 15.47619rem;
            width: 100%;
            position: absolute;
            z-index: 999;
            overflow: auto;
        }

        .wdqy-select-box ul{
            height: 100%;
            border-bottom: 1px solid #c8c8c8;
        }

        .wdqy-select-box ul li{
            background: #fff;
            left: 0;
            border-bottom: 1px solid #c8c8c8;
            height: 3.33333rem;
            line-height: 3.33333rem;
            padding-left: 0.71429rem;
            color: #333;
            font-size: 1.09524rem;
            text-align: left;
            background: #F4F4F4;
            position: relative;
            cursor: pointer;
        }

        .wdqy-select-box ul li.active:after {
            position: absolute;
            content: "";
            width: 1.07143rem;
            height: 1.07143rem;
            background: url("/static/images/icon-select-arrow.png") no-repeat;
            background-size: cover;
            right: 0.95238rem;
            top: 50%;
            margin-top: -0.54762rem;
        }
        .layui-flow-more{
            display: none;
        }
        .qyls-box2 ul > li > i.icon1 {
            background: url("/static/images/doctors.png") no-repeat;
            background-size: cover;
        }
        .qyls-box2 ul > li > .wdqy-arrow-left {
            background: url("/static/images/arrow-black-left.png") no-repeat;
            background-size: cover;
        }
        .wdqy-box ul > li .wdqy-arrow{
            background: url("/static/images/arrow-down.png") no-repeat;
            background-size: cover;
        }
        #xzqhBox .bg {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.4);
        }
        /* #yyxxBox .bg {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.4);
        }
        .my-sign-box .wdqy-select-box {
            position: fixed;
            top: 6.3rem;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 1000;
        } */
        .qyls-box2 ul > li{
            height: 5.6rem;
        }
    </style>

</head>
<body>
<section class="page-wrap my-sign-box">
    <header class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0);"><i class="iconfont icon-back"></i></a>
            </div>
            <div class="right-tool">
                <a href="javascript:void(0);"  id="toQyls"><i class="paper-icon"></i></a>
            </div>
            <div class="title">我的签约</div>
        </div>
    </header>
</section>
<div class="wdqy-box">
    <ul>
        <li id="xzqhListBox" class="wdqy-list-box" ref-target="xzqhBox" data-linkage-target="yyxxListBox">
            <span>全部区域</span>
            <i class="wdqy-arrow"></i>
        </li>
        <li id="yyxxListBox" class="wdqy-list-box" ref-target="yyxxBox">
            <span>所有医院</span>
            <i class="wdqy-arrow"></i>
        </li>
    </ul>
    <span class="wdqy-line"></span>
</div>
<div id="xzqhBox" class="wdqy-select-box" ref-target="xzqhListBox">
    <div class="bg"></div>
    <ul></ul>
</div>
<div id="yyxxBox" class="wdqy-select-box" ref-target="yyxxListBox">
    <div class="bg"></div>
    <ul></ul>
</div>
<div id="tdxxBox" class="qyls-box2">
    <ul>
    </ul>
</div>
</section>
<!-- 团队item -->
<script type="text/html" id="tdItem">
    <li>
        <i class="icon1"></i>
        <a href="javascript:void(0)" class="qyls-span-box">
            <span class="blue-span" name="tdmc"> </span>
            <span class="wdqy-span" name="jglb"></span>
            <span class="wdqy-span">累计签约人数：<span class="blue-text" name="ljqyrs"></span>人</span>
        </a>
        <a class="wdqy-arrow-left"></a>
    </li>
</script>
</body>
<script type="text/javascript">


    /**数据源*/
    function Datasource(){
        var datasource = {};
        this.set = function(ds){
            datasource = ds;
        }
        this.get = function(key, params){
            var callback = params["callback"];
            var data = datasource[key];
            if(!$.isEmptyObject(data))
            {
                delete datasource[key];
                callback(data);
            }
            else
            {
                var url = params.url;
                var queryParams = params["queryParams"];
                $.QuickRemote.AjaxJson({
                    funcName:"/api"+url
                    ,callback: function(yyxxData){
                        var ds = eval(result);
                        callback(ds);
                    }
                    ,params:queryParams
                });
            }
        }
    }



    var page_wdqy = (function($, page_wdqy) {

        /**页面数据源 行政区划与医院信息*/
        var datasource = new Datasource();
        function initView() {
            $.JkcsUtils.jsbridgeRegister("toQyls", page_wdqy.toQyls);

            $("#xzqhListBox").downListBox({
                listbox: "xzqhBox"
                ,mutualCls: "wdqy-list-box"
                ,dataLinkage: "yyxxListBox"
                ,datasource: datasource
                ,datasourceField: "xzqh"
                ,listItemTextField: "xmmc"
                ,listItemCreator: page_wdqy.createListItem
                ,emptyText: "暂无区域"
                ,dataFormat: function(data)
                {
                    if(data.length>0)
                    {
                        data.splice(0, 0, {xmdm: "", xmmc: "全部区域"});
                    }
                    else
                    {
                        data.splice(0, 0, {xmdm: "", xmmc: "暂无区域"});
                    }
                    return data;
                }
            });

            $("#yyxxListBox").downListBox({
                listbox: "yyxxBox"
                ,mutualCls: "wdqy-list-box"
                ,dataLinkage: "tdxxBox"
                ,datasource: datasource
                ,datasourceField: "yyxx"
                ,listItemTextField: "yljgmc"
                ,listItemCreator: page_wdqy.createListItem
                ,url: "/gzd/qyfw/queryTdxxByPageToJkcs"
                ,queryParamsFormater: function(data){
                    var params = {};
                    var xmdm = data.xmdm;
                    params["xzqhdm"] = xmdm;
                    params["pageSize"]="10";
                    params["pageNumber"]="1";
                    return params;
                }
                ,dataFormat: function(data)
                {
                    if(data.length>0)
                    {
                        data.splice(0, 0, {yljgdm: "", yljgmc: "所有医院"});
                    }
                    else
                    {
                        data.splice(0, 0, {yljgdm: "", yljgmc: "暂无医院"});
                    }
                    return data;
                }
            });
            $("#tdxxBox").listFlowBox({
            });
        }

        function initData() {
            page_wdqy.queryZxqyInitData();
        }

        /**加载初始化数据*/

        function queryZxqyInitData() {
            $.QuickRemote.AjaxJson({
                funcName:"/api/gzd/qyfw/queryZxqyInitData"
                ,callback: function(xzqhData){
                    $.QuickRemote.AjaxJson({
                        funcName:"/api/gzd/qyfw/queryPageYljgxx"
                        ,callback: function(yyxxData){
                            var ds = eval({xzqh:xzqhData,yyxx:yyxxData.rows});
                            datasource.set(ds);
                            $("#xzqhListBox").trigger("loadData", {key: "xzqh"});
                        }
                        ,params:{pageSize:"10",pageNumber:"1"}
                    });

                }
            });
        }

        function createListItem(ary, textField){
            var lis = [];
            if(ary && $.isArray(ary))
            {
                $.each(ary, function(index, item){
                    var text = item[textField];
                    var li = page_wdqy.createLi(text, item);
                    lis.push(li);
                })
            }
            return lis;
        }
        function createLi(text, data) {
            var li = $("<li>");
            $(li).data(data);
            var span = $("<span>");
            $(span).text(text);
            $(span).appendTo($(li));
            return $(li);
        }


        /**下拉列表*/
        function DownListBox(jq, options, params) {
            /**ID*/
            var id = $(jq).attr("id");
            /**下拉框*/
            var listboxID = options["listbox"];
            var listbox = $("#" + listboxID);
            $(listbox).hide();
            /**联动对象ID*/
            var dataLinkageID = options["dataLinkage"];
            var dataLinkage = null;
            if(!StringUtils.isEmpty(dataLinkageID))
            {
                dataLinkage = $("#"+dataLinkageID);
            }
            /**互斥class*/
            var mutualCls = "."+options["mutualCls"];
            /**数据源*/
            var datasource = options["datasource"];
            /**数据源的key*/
            var datasourceField = options["datasourceField"];
            /**下拉列表的显示字段*/
            var listItemTextField = options["listItemTextField"];
            var listItemDMField = options["listItemDMField"];
            /**下拉选项创建器*/
            var listItemCreator = options["listItemCreator"];

            var queryParamsFormater = options["queryParamsFormater"];
            var url = options["url"]?options["url"]:"/gzd/qyfw/queryTdxxByPageToJkcs";
            var dataFormat = options["dataFormat"];

            /**下拉列表元素click事件*/
            $("#" + listboxID + " ul").on("click", "li", function(){
                /**是否需要联动*/
                var linkagenable = !$(this).hasClass("active");
                $(this).addClass("active").siblings().removeClass("active");
                var text = $(this).text();
                $(jq).find("span").text(text);
                $(jq).trigger("toggleActive", {active: false, linkagenable: linkagenable});
            })

            /**点击切换激活状态*/
            $(jq).on("click", function(){
                if($(this).hasClass("active"))
                {
                    $(this).trigger("toggleActive", {active: false});
                }
                else
                {
                    $(mutualCls + "[id!=" + id + "]").trigger("toggleActive", {active: false});
                    $(this).trigger("toggleActive", {active: true});
                }
            });

            /**响应是否激活事件*/
            $(jq).on("toggleActive", function(evt, data){
                var active = data["active"];
                if(active)
                {
                    $(this).addClass("active");
                    listbox.show();
                    $(dataLinkage).trigger("toggleActive", {active: false});
                }
                else
                {
                    listbox.hide();
                    $(this).removeClass("active");
                    var linkagenable = data["linkagenable"];
                    if(linkagenable && dataLinkage)
                    {
                        var data = $(listbox).find("li.active").data();
                        $(dataLinkage).trigger("loadData", data);
                    }
                }
            })

            $(jq).on("loadData", function(evt, params){
                $(listbox).find("ul").empty();
                var queryParams = {};
                if($.isFunction(queryParamsFormater))
                {
                    queryParams = queryParamsFormater(params)
                }else{
                    var queryParams = {xzqhdm:"510601",yljgdm:"",pageSize:"10",pageNumber:"1"};
                }
                datasource.get(datasourceField, {callback: setData, url: url, queryParams: queryParams});
            })

            function setData(data)
            {
                if($.isFunction(dataFormat))
                {
                    data = dataFormat(data);
                }
                var ary = listItemCreator(data, listItemTextField);
                $(listbox).find("ul").append(ary);
                if($.isArray(ary) && ary.length>0){
                    ary[0].trigger("click");
                }
            }

            this.getSelected = function(){
                return $(listbox).find("li.active").data();
            }
        }



        function ListFlowBox(jq, options, params) {
            /**分页默认参数*/
            var pageSize = 7;
            /**当前数据*/
            var currData;
            $(jq).on("loadData", function(evt, data){
                $(jq).find("ul:eq(0)").empty();
                currData = [];
                var yydm
                if(data.yljgdm == "") {
                    yydm = data.yljgdm;
                }else{
                    yydm = data.id.yljgdm;
                }
                layui.use('flow', function(){
                    var flow = layui.flow;
                    flow.load({
                        elem: $(jq).find("ul:eq(0)")
                        ,end: " "
                        ,done: function(page, next){
                            /**当前的行政区划*/
                            var xzqhParams = $("#xzqhListBox").downListBox("getSelected");
                            var queryParams = $.extend({}, {XZQHDM: xzqhParams["xmdm"], YLJGDM: yydm,TDZT: "1", pageSize: pageSize, pageNumber: page});
                            $.QuickRemote.AjaxJson("/api/gzd/qyfw/queryTdxxByPageToJkcs", function(result){
                                var ds = eval(result);
                                var total = ds["total"];
                                var allPage = Math.ceil(total/pageSize);
                                var rows = ds["rows"];
                                currData = currData.concat(rows);
                                var items = createItems(rows);
                                var content = items.join("");
                                var more = allPage>page?true:false;

                                next(content, more);
                            }, queryParams);
                        }
                    });
                });
            });

            $(jq).on("click", "li", function(){
//			var index = $(this).index();
//            var data = currData[index];
//            console.log(data);
                var data=JSON.parse($(this).attr("tdxx"));
                console.log(data);
                StoreCache.setCache("QYFW_TDXX", data);
                StoreCache.setCache("YLJGID",data.YLJGID);
                $.pageSwitch.goToUrl("mySignService","tdjj");
            });

            function createItems(rows)
            {
                var items = [];
                $.each(rows, function(index, item){
                    StoreCache.setCache("xzqhdm", item.xzqhdm);
                    var YYXX = item["yljgmc"]+"(类别：" + item["jglb"] + ")";
                    item["YYXX"] = YYXX;
                    var tdItem = $($("#tdItem").html());
                    $(tdItem).find("span[name]").each(function(){
                        var name = $(this).attr("name");
                        var text = item[name];
                        var str = JSON.stringify(item);
                        $(tdItem).attr("tdxx", str);
                        $(this).text(text);
                    })
                    items.push($(tdItem).prop("outerHTML"));
                })
                return items;
            }
        }

        function toQyls(){
            $.pageSwitch.goToUrl("mySignService","qyls");
        }

        var cfg_def = {
            initView: initView,
            initData: initData,
            queryZxqyInitData: queryZxqyInitData,
            createListItem: createListItem,
            createLi: createLi,
            DownListBox: DownListBox,

            ListFlowBox: ListFlowBox,
            toQyls: toQyls,
        }

        page_wdqy.init = function(cfg){
            $.extend(page_wdqy, cfg_def, cfg);


            $.fn.downListBox = function(options, params){
                var obj = $(this).data("DownListBox");
                if ($.isEmptyObject(obj))
                {
                    obj = new page_wdqy.DownListBox(this, options, params);
                    $(this).data("DownListBox", obj);
                }
                if ($.type(options) == "string")
                {
                    return obj[options](params);
                }
                return this.each(function()
                {
                });
            }


            /**列表*/
            $.fn.listFlowBox = function(options, params){
                var obj = $(this).data("ListFlowBox");
                if ($.isEmptyObject(obj))
                {
                    new page_wdqy.ListFlowBox(this, options, params);
                }
                if ($.type(options) == "string")
                {
                    return obj[options](params);
                }
                return this.each(function()
                {
                });
            }
            $("#toQyls").click(page_wdqy.toQyls)
            page_wdqy.initView();
            page_wdqy.initData();

        }

        return page_wdqy;
    })(jQuery, {});
    

</script>
</html>












